package com.example.websocket_demo.service.user;

import com.example.websocket_demo.dao.user.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserDao userDao;

    @Override
    public int insertUser(Map<String, Object> userMap) {
        return userDao.insertUser(userMap);
    }

    @Override
    public Map<String, Object> signUp(Map<String, Object> userMap) {
        Map<String, Object> res=new HashMap<>();
        Map<String, Object> map=new HashMap<>();
        map.put("email",userMap.get("email"));
        if(userDao.selectUser(map).size()>0){
            res.put("resStatus",-1);
            res.put("msg","注册失败");
        }else{
            res.put("resStatus",userDao.insertUser(userMap));
            res.put("msg","注册成功");
        }
        return res;
    }

    @Override
    public Map<String, Object> signIn(Map<String, Object> userMap) {
        Map<String, Object> res=new HashMap<>();
        /*
        * 邮箱+密码登陆
        * */
        List<Map<String,Object>> list=userDao.selectUser(userMap);
        if(list.size()==0){
            res.put("resStatus",-1);
            res.put("msg","登陆失败");
        }else{
            res=list.get(0);
            res.put("resStatus",1);
            res.put("msg","登陆成功");
        }
        return res;
    }

    @Override
    public int deleteUser(Integer id) {
        return 0;
    }

    @Override
    public int updateUser(Map<String, Object> userMap) {
        return 0;
    }

    @Override
    public List<Map<String, Object>> selectUser(Map<String, Object> userMap) {
        return userDao.selectUser(userMap);
    }

    @Override
    public List<Map<String, Object>> selectUsers() {
        return null;
    }
}
